package DatabaseAdaptor;

import java.io.File;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;

public class DatabaseAdaptor {
	private SQLiteDatabase db;
	public DatabaseAdaptor(){
        String newFolder = "/shimmer-data";
        String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
        File myNewFolder = new File(extStorageDirectory + newFolder);
        
        myNewFolder.mkdir();
        
        File dbfile = new File("/sdcard/shimmer-data/Accelerometry.db" ); 
        db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);
        System.out.println("Its open? "  + db.isOpen());
		
	}
	public  boolean createTable(String tableName){

        String sql = "CREATE TABLE IF NOT EXISTS " + tableName + "("
				+ "id" + " INTEGER PRIMARY KEY," + "timestamp" + " TEXT," + "x" + " INT," + "y" + " INT," + "z" + " INT," + "ECG" + " INT" + ")";
        db.execSQL(sql );        
        return true;
		
	}
	public boolean insertAccelerometryData(int timestamp,int x, int y,int z){
			ContentValues values = new ContentValues();
			values.put("timestamp", timestamp); 
			values.put("x", x);
			values.put("y", y);
			values.put("z", z);
			// Inserting Row
			db.insert("accelerometry", null, values);
			return true;
	}
	public boolean deleteAllData(){
        String sql = "DELETE FROM accelerometry WHERE 1";
		db.execSQL(sql );        
		
		return true;
	}

}
